<template>
	<view class="my-con">
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<view class="my-top">
			<view class="ava-box">
				<image src="/static/images/tx.png" mode="widthFix"></image>
			</view>
			<view class="my-text">
				<text>{{userInfo.nickName}}</text>
			</view>
		</view>

		<view class="my-list">
			<view class="my-item" v-for="(item,index) in itemData" @click="item.name=='体测训练'?gotoTcz():gotoPage(item)">
				<view class="my-l">
					<image :src="'/static/images/my'+index+'.png'" mode="widthFix"></image>
					<text>{{item.name}}</text>
				</view>
				<image src="/static/images/icon1.png" mode="widthFix"></image>
			</view>
			<view class="my-item" @click="gotoSw">
				<view class="my-l">
					<image src="/static/images/my4.png" mode="widthFix"></image>
					<text>成绩列表</text>
				</view>
				<image src="/static/images/icon1.png" mode="widthFix"></image>
			</view>
			<view class="my-item" @click="goOut">
				<view class="my-l">
					<image src="/static/images/my5.png" mode="widthFix"></image>
					<text>退出登录</text>
				</view>
				<image src="/static/images/icon1.png" mode="widthFix"></image>
			</view>
		</view>
		
		<!-- 弹窗 -->
		<showModelVue ref="modelPopup" :textWord="'确认要退出登录吗'" @bindChange='outBtn'></showModelVue>
	</view>
</template>

<script>
	import showModelVue from '../../components/showModel.vue'
	export default {
		components:{showModelVue},
		data() {
			return {
				isTc:false,
				tcDataId:'',
				itemData:[
					// {name:'学生建档',url:'/pages/student/createX'},
					// {name:'开启体测',url:'/pages/index/temporary'},
					{name:'体测训练',url:'/pages/score/results'},
					{name:'设备列表',url:'/pages/index/device'},
				],
				userInfo:{}
			}
		},
		onLoad() {

		},
		onShow() {
			this.getTc()
			this.getUser()
		},
		methods: {
			async getTc(){
				let res = await this.http("get","/tc/tcOperate/getTcqueueList")
				console.log(res)
				if(res.code==200){
					const findChineseStatus1Index = res.data.findIndex(item =>
					  item.status === '1'
					);
					if(findChineseStatus1Index == -1){
						this.isTc = false
					}else{
						this.isTc = true
						this.tcData = res.data[findChineseStatus1Index]
					}
				}
			},
			async getUser(){
				let res = await this.http('get','/system/user/getInfo')
				console.log(res)
				if(res.code==200){
					this.userInfo = res.user
				}
			},
			gotoTcz(){
				if(this.isTc){
					uni.navigateTo({
						url: '/pages/score/results?id='+this.tcData.id+'&pid='+this.tcData.pro+'&devices='+this.tcData.device
					})
				}else{
					this.toast('没有进行的训练')
				}
			},
			gotoPage(row) {
				uni.navigateTo({
					url: row.url
				})
			},
			gotoSw(){
				uni.switchTab({
					url:'/pages/score/score'
				})
			},
			goOut() {
				this.$refs.modelPopup.openModel()
			},
			async outBtn(){
				let that = this
				let res = await that.http('delete','/auth/logout')
				if(res.code==200){
					that.toast('退出成功')
					uni.navigateTo({
						url:'/pages/login/login'
					})
				}
			}
		}
	}
</script>

<style lang="less">
	page{
		width: 100%;
		height: 100%;
	}
	.my-con {
		width: 100%;
		min-height: 100%;
		padding: 40upx;
		box-sizing: border-box;
		background: url('/static/images/bg5.png') no-repeat;
		background-size: 100%;
	}
	.my-top{
		width: 100%;
		display: flex;
		align-items: center;
		margin: 60upx 0;
		.ava-box{
			width: 120upx;
			height: 120upx;
			border-radius: 50%;
			overflow: hidden;
			margin-right: 40upx;
			image{
				width: 100%;
			}
		}
		.my-text{
			text{
				font-size: 40upx;
			}
		}
	}
	.my-list{
		width: 100%;
		background-color: #fff;
		border-radius: 18upx;
		padding: 10upx 40upx;
		box-sizing: border-box;
		.my-item{
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 40upx 0;
			.my-l{
				display: flex;
				align-items: center;
				image{
					width: 32upx;
					height: auto;
					display: block;
					margin-right: 20upx;
				}
				text{
					font-size: 32upx;
				}
			}
			>image{
				width: 32upx;
				height: auto;
			}
		}
	}
</style>